package org.cheetah.core.exchange;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Message implements Serializable, Cloneable {
	private static final long serialVersionUID = 2722839646850923211L;

	private Map<String, Object> properties;

	private Object message;

	public Message() {
		properties = new ConcurrentHashMap<String, Object>();
	}

	public Message(Object message) {
		this.properties = new ConcurrentHashMap<String, Object>();
		this.message = message;
	}

	Message(Message exchange) {
		properties = new ConcurrentHashMap<String, Object>(exchange.properties);
		message = exchange.message;
	}

	public Object getProperty(String name) {
		return properties.get(name);
	}

	public void setProperty(String name, Object value) {
		properties.put(name, value);
	}

	public void removeProperty(String name) {
		properties.remove(name);
	}

	public Map<String, Object> getProperties() {
		return properties;
	}

	public void clear() {
		properties.clear();
		message = null;
	}

	public Object getMessage() {
		return message;
	}

	public void setMessage(Object message) {
		this.message = message;
	}

	@Override
	public Object clone() {
		return new Message(this);
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		sb.append(super.toString()).append("\nproperties\n").append(properties)
				.append("\nmessage\n").append(message);

		return sb.toString();
	}
}
